// Copyright (c) Microsoft Corporation and Contributors.
// Licensed under the MIT License.

using CommunityToolkit.WinUI.UI.Controls;
using Microsoft.UI.Xaml.Controls;
using WhaleAccount.ViewModels;

// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.

namespace WhaleAccount.Views;
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class BillPage : Page
{
    public BillViewModel ViewModel
    {
        get;
    }
    public BillPage()
    {
        ViewModel = App.GetService<BillViewModel>();
        InitializeComponent();

        DatePicker.Date = DateTime.Now;
        ViewModel.EnsureItemSelected();
    }

    private void DatePicker_SelectedDateChanged(DatePicker sender, DatePickerSelectedValueChangedEventArgs args)
    {
        if (args.NewDate != null)
        {
            var value = args.NewDate.Value;
            ViewModel.LoadData(value.Year);
            ViewModel.EnsureItemSelected();
        }
    }

    private void OnViewStateChanged(object sender, ListDetailsViewState e)
    {
        if (e == ListDetailsViewState.Both)
        {
            ViewModel.EnsureItemSelected();
        }
    }
}
